import 'package:flutter/material.dart';
import 'app_colors.dart';

/// 应用文字样式配置
/// App text styles configuration
class AppTextStyles {
  // 私有构造函数，防止实例化
  // Private constructor to prevent instantiation
  AppTextStyles._();

  // ==================== 基础字体配置 Base Font Configuration ====================
  
  /// 默认字体家族
  /// Default font family
  static const String defaultFontFamily = 'PingFang SC';
  
  /// 备用字体家族
  /// Fallback font families
  static const List<String> fallbackFontFamilies = [
    'Helvetica Neue',
    'Arial',
    'sans-serif',
  ];
  
  // ==================== Display 样式 Display Styles ====================
  
  /// 超大标题样式
  /// Display large style
  static const TextStyle displayLarge = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 57,
    fontWeight: FontWeight.w400,
    letterSpacing: -0.25,
    height: 1.12,
    color: AppColors.onBackground,
  );
  
  /// 大标题样式
  /// Display medium style
  static const TextStyle displayMedium = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 45,
    fontWeight: FontWeight.w400,
    letterSpacing: 0,
    height: 1.16,
    color: AppColors.onBackground,
  );
  
  /// 中等标题样式
  /// Display small style
  static const TextStyle displaySmall = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 36,
    fontWeight: FontWeight.w400,
    letterSpacing: 0,
    height: 1.22,
    color: AppColors.onBackground,
  );
  
  // ==================== Headline 样式 Headline Styles ====================
  
  /// 大标题样式
  /// Headline large style
  static const TextStyle headlineLarge = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 32,
    fontWeight: FontWeight.w500,
    letterSpacing: 0,
    height: 1.25,
    color: AppColors.onSurface,
  );
  
  /// 中等标题样式
  /// Headline medium style
  static const TextStyle headlineMedium = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 28,
    fontWeight: FontWeight.w500,
    letterSpacing: 0,
    height: 1.29,
    color: AppColors.onSurface,
  );
  
  /// 小标题样式
  /// Headline small style
  static const TextStyle headlineSmall = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 24,
    fontWeight: FontWeight.w500,
    letterSpacing: 0,
    height: 1.33,
    color: AppColors.onSurface,
  );
  
  // ==================== Title 样式 Title Styles ====================
  
  /// 大标题样式
  /// Title large style
  static const TextStyle titleLarge = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 22,
    fontWeight: FontWeight.w600,
    letterSpacing: 0,
    height: 1.27,
    color: AppColors.onSurface,
  );
  
  /// 中等标题样式
  /// Title medium style
  static const TextStyle titleMedium = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 16,
    fontWeight: FontWeight.w600,
    letterSpacing: 0.15,
    height: 1.5,
    color: AppColors.onSurface,
  );
  
  /// 小标题样式
  /// Title small style
  static const TextStyle titleSmall = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 14,
    fontWeight: FontWeight.w600,
    letterSpacing: 0.1,
    height: 1.43,
    color: AppColors.onSurface,
  );
  
  // ==================== Body 样式 Body Styles ====================
  
  /// 大正文样式
  /// Body large style
  static const TextStyle bodyLarge = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 16,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.5,
    height: 1.5,
    color: AppColors.onSurface,
  );
  
  /// 中等正文样式
  /// Body medium style
  static const TextStyle bodyMedium = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 14,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.25,
    height: 1.43,
    color: AppColors.onSurface,
  );
  
  /// 小正文样式
  /// Body small style
  static const TextStyle bodySmall = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.4,
    height: 1.33,
    color: AppColors.onSurface,
  );
  
  // ==================== Label 样式 Label Styles ====================
  
  /// 大标签样式
  /// Label large style
  static const TextStyle labelLarge = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 14,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.1,
    height: 1.43,
    color: AppColors.onSurface,
  );
  
  /// 中等标签样式
  /// Label medium style
  static const TextStyle labelMedium = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.5,
    height: 1.33,
    color: AppColors.onSurface,
  );
  
  /// 小标签样式
  /// Label small style
  static const TextStyle labelSmall = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 11,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.5,
    height: 1.45,
    color: AppColors.onSurface,
  );
  
  // ==================== 特殊样式 Special Styles ====================
  
  /// 按钮文字样式
  /// Button text style
  static const TextStyle button = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 14,
    fontWeight: FontWeight.w600,
    letterSpacing: 0.1,
    height: 1.43,
    color: AppColors.onPrimary,
  );
  
  /// 标题栏文字样式
  /// App bar title style
  static const TextStyle appBarTitle = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 20,
    fontWeight: FontWeight.w600,
    letterSpacing: 0,
    height: 1.2,
    color: AppColors.onSurface,
  );
  
  /// 底部导航栏文字样式
  /// Bottom navigation label style
  static const TextStyle bottomNavLabel = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.5,
    height: 1.33,
    color: AppColors.onSurface,
  );
  
  /// 卡片标题样式
  /// Card title style
  static const TextStyle cardTitle = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 18,
    fontWeight: FontWeight.w600,
    letterSpacing: 0,
    height: 1.33,
    color: AppColors.onSurface,
  );
  
  /// 卡片副标题样式
  /// Card subtitle style
  static const TextStyle cardSubtitle = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 14,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.25,
    height: 1.43,
    color: AppColors.onSurface,
  );
  
  /// 输入框提示文字样式
  /// Input hint text style
  static TextStyle inputHint = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 16,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.5,
    height: 1.5,
    color: AppColors.onSurface.withOpacity(0.6),
  );
  
  /// 输入框标签样式
  /// Input label style
  static TextStyle inputLabel = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.4,
    height: 1.33,
    color: AppColors.onSurface.withOpacity(0.8),
  );
  
  /// 错误文字样式
  /// Error text style
  static const TextStyle error = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.4,
    height: 1.33,
    color: AppColors.error,
  );
  
  /// 成功文字样式
  /// Success text style
  static const TextStyle success = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.4,
    height: 1.33,
    color: AppColors.success,
  );
  
  /// 警告文字样式
  /// Warning text style
  static const TextStyle warning = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.4,
    height: 1.33,
    color: AppColors.warning,
  );
  
  /// 信息文字样式
  /// Info text style
  static const TextStyle info = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.4,
    height: 1.33,
    color: AppColors.info,
  );
  
  // ==================== 情绪相关样式 Emotion Related Styles ====================
  
  /// 情绪标题样式
  /// Emotion title style
  static const TextStyle emotionTitle = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 20,
    fontWeight: FontWeight.w600,
    letterSpacing: 0,
    height: 1.2,
    color: AppColors.onSurface,
  );
  
  /// 情绪强度样式
  /// Emotion intensity style
  static const TextStyle emotionIntensity = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 16,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.15,
    height: 1.5,
    color: AppColors.primary,
  );
  
  /// 日记内容样式
  /// Diary content style
  static const TextStyle diaryContent = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 16,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.5,
    height: 1.6,
    color: AppColors.onSurface,
  );
  
  /// 时间戳样式
  /// Timestamp style
  static TextStyle timestamp = TextStyle(
    fontFamily: defaultFontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.4,
    height: 1.33,
    color: AppColors.onSurface.withOpacity(0.6),
  );
  
  // ==================== 工具方法 Utility Methods ====================
  
  /// 根据字体大小倍数调整样式
  /// Adjust style by font size multiplier
  static TextStyle adjustFontSize(TextStyle style, double multiplier) {
    return style.copyWith(
      fontSize: (style.fontSize ?? 14) * multiplier,
    );
  }
  
  /// 获取带颜色的样式
  /// Get style with color
  static TextStyle withColor(TextStyle style, Color color) {
    return style.copyWith(color: color);
  }
  
  /// 获取带权重的样式
  /// Get style with font weight
  static TextStyle withWeight(TextStyle style, FontWeight weight) {
    return style.copyWith(fontWeight: weight);
  }
  
  /// 获取带透明度的样式
  /// Get style with opacity
  static TextStyle withOpacity(TextStyle style, double opacity) {
    return style.copyWith(
      color: (style.color ?? AppColors.onSurface).withOpacity(opacity),
    );
  }
  
  /// 获取情绪颜色的文字样式
  /// Get text style with emotion color
  static TextStyle withEmotionColor(TextStyle style, String emotionType) {
    return style.copyWith(
      color: AppColors.getEmotionColor(emotionType),
    );
  }
  
  /// 获取强调样式
  /// Get emphasized style
  static TextStyle emphasized(TextStyle style) {
    return style.copyWith(
      fontWeight: FontWeight.w600,
      color: AppColors.primary,
    );
  }
  
  /// 获取次要样式
  /// Get secondary style
  static TextStyle secondary(TextStyle style) {
    return style.copyWith(
      color: (style.color ?? AppColors.onSurface).withOpacity(0.7),
    );
  }
  
  /// 获取禁用样式
  /// Get disabled style
  static TextStyle disabled(TextStyle style) {
    return style.copyWith(
      color: (style.color ?? AppColors.onSurface).withOpacity(0.38),
    );
  }
  
  /// 根据主题模式获取样式
  /// Get style by theme mode
  static TextStyle forTheme(TextStyle style, bool isDark) {
    if (isDark) {
      return style.copyWith(
        color: _getDarkThemeColor(style.color ?? AppColors.onSurface),
      );
    }
    return style;
  }
  
  /// 获取深色主题对应的颜色
  /// Get corresponding dark theme color
  static Color _getDarkThemeColor(Color lightColor) {
    if (lightColor == AppColors.onSurface) {
      return AppColors.onSurfaceDark;
    } else if (lightColor == AppColors.onBackground) {
      return AppColors.onBackgroundDark;
    } else if (lightColor == AppColors.primary) {
      return AppColors.primaryDark;
    } else if (lightColor == AppColors.secondary) {
      return AppColors.secondaryDark;
    }
    return lightColor;
  }
  
  /// 获取响应式字体大小
  /// Get responsive font size
  static double getResponsiveFontSize(double baseFontSize, double screenWidth) {
    // 基于屏幕宽度的响应式字体大小计算
    // Responsive font size calculation based on screen width
    if (screenWidth < 360) {
      return baseFontSize * 0.9;
    } else if (screenWidth > 600) {
      return baseFontSize * 1.1;
    }
    return baseFontSize;
  }
  
  /// 获取可访问性友好的样式
  /// Get accessibility-friendly style
  static TextStyle accessible(TextStyle style) {
    return style.copyWith(
      fontSize: (style.fontSize ?? 14) >= 14 ? style.fontSize : 14,
      height: (style.height ?? 1.4) >= 1.4 ? style.height : 1.4,
    );
  }
}